package com.ruoyi.file.config;

import com.aliyun.oss.OSS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliOssConfig {

    /**
     * Bucket Name of OSS Example.
     */
    public static final String BUCKET_NAME = "yong-bucket921";

    @Autowired
    private OSS ossClient;

    /**
     * You can use these code to check or create oss bucket. Or manage buckets in
     * <a href="https://oss.console.aliyun.com/bucket">oss console</a>.
     */
    @Bean
    public ApplicationRunner ossBucketInitRunner() {
        return args -> {
            if (!ossClient.doesBucketExist(BUCKET_NAME)) {
                ossClient.createBucket(BUCKET_NAME);
            }
        };
    }
}
